package com.nursebetty.server.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import com.nursebetty.server.common.UserProfile;
import com.nursebetty.server.dao.WeightLostDao;
import com.nursebetty.server.model.WeightLost;


public class WeightLostDaoImpl implements WeightLostDao {
	private JdbcTemplate jdbcTemplate;

	
	public void setDataSource(DataSource dataSource) {
        this.jdbcTemplate = new JdbcTemplate(dataSource);
    }


	public List<WeightLost> getResults(UserProfile user) {
		String sql ="select * from WEIGHT_TRACK_ENTRY where USR_ID = " + user.getId();
		List<WeightLost> result = this.jdbcTemplate.query(sql, new WeighLostMapper());
		return result;
	}

	public String saveResults(WeightLost weightLost, UserProfile user, String Result) {
		// TODO Auto-generated method stub
		return null;
	}

	public void saveWeightLost(UserProfile user, WeightLost weightLost) {
		String sql="insert into WEIGHT_TRACK_ENTRY(USR_ID,WEIGHT_ENTRY,HEIGHT_ENTRY,WEIGHT_RESULT) values (?, ?, ?, ?) ";
		jdbcTemplate.execute(sql);

	}
	
	private static final class WeighLostMapper implements RowMapper {

		public WeightLost mapRow(ResultSet rs, int rowNum) throws SQLException {
			WeightLost wl = new WeightLost();
			wl.setWeight(rs.getInt("WEIGHT_RESULT"));
			return wl;
		}
	}


}
